<!--支付通知管理-->
<template>
  <div id="businessPayNotify" class="app-container">
    <!--搜索条件-->
    <div class="filter-container">
      <el-form :model="listQuery" :inline="true">
        <el-form-item label="关键字">
          <el-input v-model="listQuery.keyword" clearable placeholder="请输入完整单号或交易号" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="通知时间">
          <el-date-picker
            v-model="notifyDates"
            type="daterange"
            align="right"
            unlink-panels
            value-format="timestamp"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" plain @click="handleFilter">搜索</el-button>
          <el-button icon="el-icon-refresh" plain @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--列表-->
    <div class="table-container flex-main">
      <el-tabs v-model="listQuery.notifyType" class="common-tabs" @tab-click="handleTabClick">
        <el-tab-pane label="付款" name="pay" />
        <el-tab-pane label="退款" name="refund" />
        <el-tab-pane label="转账" name="transfer" />
      </el-tabs>
      <div class="table-container-header">
        <table-toolbar :create="false" :remove="false" @refresh="handleFilter" />
      </div>
      <el-table
        ref="multipleTable"
        :data="list"
        header-cell-class-name="table-header"
        fit
        height="100%"
        highlight-current-row
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
        @sort-change="sortChange"
      >
        <el-table-column type="selection" width="60" />
        <el-table-column align="center" prop="id" label="#" width="60">
          <template slot-scope="scope">{{ scope.$index+1 }}</template>
        </el-table-column>
        <el-table-column prop="notifyDate" sortable label="通知时间" width="160">
          <template slot-scope="scope">{{ scope.row.notifyDate | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>
        </el-table-column>
        <el-table-column prop="notifyType" sortable label="通知类型" width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.notifyType==='pay'" class="color-primary">付款</span>
            <span v-if="scope.row.notifyType==='refund'" class="color-warning">退款</span>
            <span v-if="scope.row.notifyType==='transfer'" class="color-default">转账</span>
          </template>
        </el-table-column>
        <el-table-column label="渠道" prop="channelPayWay" width="100" sortable show-overflow-tooltip />
        <el-table-column label="通知内容" prop="notifyContent" min-width="200" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tooltip class="item" effect="light" placement="bottom">
              <div slot="content">
                <json-viewer :value="JSON.parse(scope.row.notifyContent)" />
              </div>
              <el-link type="primary" :underline="false">通知详情</el-link>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination_handler">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />
    </div>
  </div>
</template>

<script>
import JsonViewer from 'vue-json-viewer'

export default {
  components: { JsonViewer },

  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      notifyDates: [],
      list: [],
      total: 0,
      listQuery: {
        page: 1,
        limit: 20,
        keyword: undefined,
        notifyDateStart: null,
        notifyDateEnd: null,
        sort: '-notifyDate',
        notifyType: 'pay'

      },

      multipleSelectionRecords: [],
      // 固定写法
      sideBox: {
        recordShow: false,
        title: '',
        status: 'create'
      },
      businessPayNotifyRecord: {}
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    handleTabClick() {
      this.handleFilter()
    },
    // 表格自带方法开始
    /* 全选/反选*/
    handleSelectionChange(val) {
      this.multipleSelectionRecords = val
    },
    /* 表格行数据单击*/
    handleRowClick(row) {
      this.$refs.multipleTable.toggleRowSelection(row)
    },
    /* 表格列排序*/
    sortChange(data) {
      const { prop, order } = data
      if (prop) {
        if (order === 'ascending') {
          this.listQuery.sort = '+' + prop
        } else {
          this.listQuery.sort = '-' + prop
        }
      } else {
        this.listQuery.sort = '-notifyDate'
      }
      this.handleFilter()
    },
    // 表格自带方法结束

    /* 搜索*/
    handleFilter() {
      this.listQuery = {
        ...this.listQuery,
        page: 1
      }
      this.fetchData()
    },
    /* 重置*/
    handleReset() {
      this.listQuery = {
        ...this.listQuery,
        page: 1,
        limit: 20,
        keyword: undefined,
        notifyDateStart: null,
        notifyDateEnd: null,
        sort: '-notifyDate'
      }
      this.notifyDates = []
      this.$refs.multipleTable.clearFilter()
      this.$refs.multipleTable.clearSort()
      this.fetchData()
    },
    async fetchData() {
      if (this.notifyDates.length === 2) {
        this.listQuery = {
          ...this.listQuery,
          notifyDateStart: this.notifyDates[0],
          notifyDateEnd: this.notifyDates[1]
        }
      }
      const response = await this.$store.dispatch('businessPayNotifyPage', this.listQuery)
      this.list = response.records
      this.total = response.total
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
